package com.example.front.controller;

import com.example.api.pojo.BaseInfo;
import com.example.common.Constans.RedisKey;
import com.example.common.util.CommonUtil;
import com.example.front.view.RespResult;
import com.example.front.view.inverst.RankView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * 有关投资的功能
 * @Author cjk
 * @Date 2024 07 30 23 11
 **/
@Api(tags={"投资理财产品"})
@RestController
public class InverstController extends BaseController{

    /**投资排行榜*/
    @ApiOperation(value = "投资排行榜",notes = "显示前三位 投资人")
    @GetMapping("/v1/inverst/rank")
    public RespResult showInverstRank(){
        //从redis中查询数据
        Set<ZSetOperations.TypedTuple<String>> sets = stringRedisTemplate.boundZSetOps(RedisKey.KEY_INVERST_RANK).reverseRangeByScoreWithScores(0, 2);

        List<RankView> rankViewList = new ArrayList<>();
        //遍历set集合
        sets.forEach( tuple -> {
            rankViewList.add(new RankView(CommonUtil.tuoMinPhone(tuple.getValue()),tuple.getScore()));
        });
        RespResult result = RespResult.success();
        result.setList(rankViewList);

        return result;
    }

}
